# class single:
#     _instance=None
#     def __new__(cls, *args, **kwargs):
#         #表示没有创建过,调用父类new方法给__instance赋值
#         #if cls.__instance==None:这里不要这么写
#         if cls._instance is None:
#             cls._instance=super().__new__(cls)
#             # 注意：这里不需要else分支，因为无论if条件是否满足，最终都会返回_instance
#         return cls._instance
#
#
# s1=single()
# s2=single()
# print(s1 is s2)




















#自己写的
class single:
    _isinstance=None
    def __new__(cls, *args, **kwargs):
        if cls._isinstance==None:
            cls._isinstance=super().__new__(cls)
        return cls._isinstance

s1=single()
s2=single()
print(s1==s2)


















